﻿using System;
using System.Collections;
using System.Collections.Generic;
using dk2Database;
using dk2Repository;
using dk2Repository.Example.BL;

namespace dk2Repository.Example.DAL
{


    internal class UserData : Repository<User>
    {


        public static IList<User> SelectByGender(User.enumGender gender)
        {
            return Select("Gender = ?", "Users.Name DESC", (int)User.enumGender.Female);
        }

        public static IList<User> SelectAllChangeGender()
        {
            return Query((values, user) =>
                              {
                                  user.Gender = ((user.Gender == User.enumGender.Female) ? User.enumGender.Male : User.enumGender.Female);
                                  return user;

                              }, "SELECT * FROM Users");
        }




        public static List<User> SelectUsingReader()
        {
            return Database.Query((rdr) =>
            {
                var users = new List<User>();

                while (rdr.Read())
                {
                    var user = new User();
                    user.Name = rdr[0].ToString();
                    user.Department = new Department();
                    user.Department.Name = rdr[1].ToString();
                    users.Add(user);
                }
                return users;

            }, "SELECT u.Name, d.Name FROM Users u INNER JOIN Departments d ON u.DepartmentId = d.Id");
        }





    }
}